package com.jingdianjichi.practice.api.common;

import lombok.Data;

//返回统一的返回数据,同理这些在auth-common的东西也是可以抽取出来的,因为这些也是仅仅对Controller层开放的,我们在这里裁剪过来
@Data
public class Result<T> {
    private Boolean success;

    private Integer code;

    private String message;

    private T data;

    //返回成功的
    public static Result ok(){
        Result result=new Result();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getDesc());

        return result;
    }

    //返回有数据的
    public static <T> Result ok(T data){
        Result result=new Result();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
        result.setData(data);

        return result;
    }

    //失败的返回
    public static Result fail(){
        Result result=new Result();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(ResultCodeEnum.FAIL.getDesc());

        return result;
    }

    //返回有数据的
    public static <T> Result fail(T data){
        Result result=new Result();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(ResultCodeEnum.FAIL.getDesc());
        result.setData(data);

        return result;
    }
}
